Electrical Engineering (EE) Exam  >  Electrical Engineering (EE) Questions  >  What will be the output of the following code... Start Learning for Free
What will be the output of the following code snippet?
#include <stdio.h>
void solve() {
    int first = 10, second = 20;
    int third = first + second;
    {
        int third = second - first;
        printf("%d ", third);
    }
    printf("%d", third);
}
int main() {
    solve();
    return 0;
}
  • a)
    10 30
  • b)
    30 10
  • c)
    10 20
  • d)
    20 10
Correct answer is option 'A'. Can you explain this answer?
Verified Answer
What will be the output of the following code snippet?#include <std...
  • Inside the solve() function, two variables first and second are declared and assigned the values of 10 and 20, respectively. Then, a new variable third is declared and assigned the value of first + second, which is 30.
  • Next, a new block is created using curly braces {}, and inside this block, another variable third is declared and assigned the value of second - first, which is 10. Then, the value of this inner third variable is printed using printf("%d ", third);, resulting in the output of 10.
  • After that, the program continues execution outside the inner block, and the value of the outer third variable is printed using printf("%d", third);, resulting in the output of 30.
  • Therefore, the correct output is 1: 10 30.
View all questions of this test
Most Upvoted Answer
What will be the output of the following code snippet?#include <std...


Explanation:

Variable Declaration:
- Two integer variables 'first' and 'second' are declared and initialized with values 10 and 20 respectively.
- Another integer variable 'third' is declared and assigned the sum of 'first' and 'second'.

Inner Scope:
- Inside a nested block, a new integer variable 'third' is declared and assigned the difference of 'second' and 'first'.
- This inner 'third' variable is printed within the nested block.

Output:
- The inner 'third' variable (which is '20 - 10 = 10') is printed first.
- Then, outside the nested block, the original 'third' variable (which is '10 + 20 = 30') is printed.
- So, the output of the code will be: 10 30.

Therefore, the correct answer is option 'A) 10 30'.
Free Test
Community Answer
What will be the output of the following code snippet?#include <std...
  • Inside the solve() function, two variables first and second are declared and assigned the values of 10 and 20, respectively. Then, a new variable third is declared and assigned the value of first + second, which is 30.
  • Next, a new block is created using curly braces {}, and inside this block, another variable third is declared and assigned the value of second - first, which is 10. Then, the value of this inner third variable is printed using printf("%d ", third);, resulting in the output of 10.
  • After that, the program continues execution outside the inner block, and the value of the outer third variable is printed using printf("%d", third);, resulting in the output of 30.
  • Therefore, the correct output is 1: 10 30.
Explore Courses for Electrical Engineering (EE) exam
Question Description
What will be the output of the following code snippet?#include <stdio.h>void solve() { int first = 10, second = 20; int third = first + second; { int third = second - first; printf("%d ", third); } printf("%d", third);}int main() { solve(); return 0;}a)10 30b)30 10c)10 20d)20 10Correct answer is option 'A'. Can you explain this answer? for Electrical Engineering (EE) 2025 is part of Electrical Engineering (EE) preparation. The Question and answers have been prepared according to the Electrical Engineering (EE) exam syllabus. Information about What will be the output of the following code snippet?#include <stdio.h>void solve() { int first = 10, second = 20; int third = first + second; { int third = second - first; printf("%d ", third); } printf("%d", third);}int main() { solve(); return 0;}a)10 30b)30 10c)10 20d)20 10Correct answer is option 'A'. Can you explain this answer? covers all topics & solutions for Electrical Engineering (EE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for What will be the output of the following code snippet?#include <stdio.h>void solve() { int first = 10, second = 20; int third = first + second; { int third = second - first; printf("%d ", third); } printf("%d", third);}int main() { solve(); return 0;}a)10 30b)30 10c)10 20d)20 10Correct answer is option 'A'. Can you explain this answer?.
Solutions for What will be the output of the following code snippet?#include <stdio.h>void solve() { int first = 10, second = 20; int third = first + second; { int third = second - first; printf("%d ", third); } printf("%d", third);}int main() { solve(); return 0;}a)10 30b)30 10c)10 20d)20 10Correct answer is option 'A'. Can you explain this answer? in English & in Hindi are available as part of our courses for Electrical Engineering (EE). Download more important topics, notes, lectures and mock test series for Electrical Engineering (EE) Exam by signing up for free.
Here you can find the meaning of What will be the output of the following code snippet?#include <stdio.h>void solve() { int first = 10, second = 20; int third = first + second; { int third = second - first; printf("%d ", third); } printf("%d", third);}int main() { solve(); return 0;}a)10 30b)30 10c)10 20d)20 10Correct answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of What will be the output of the following code snippet?#include <stdio.h>void solve() { int first = 10, second = 20; int third = first + second; { int third = second - first; printf("%d ", third); } printf("%d", third);}int main() { solve(); return 0;}a)10 30b)30 10c)10 20d)20 10Correct answer is option 'A'. Can you explain this answer?, a detailed solution for What will be the output of the following code snippet?#include <stdio.h>void solve() { int first = 10, second = 20; int third = first + second; { int third = second - first; printf("%d ", third); } printf("%d", third);}int main() { solve(); return 0;}a)10 30b)30 10c)10 20d)20 10Correct answer is option 'A'. Can you explain this answer? has been provided alongside types of What will be the output of the following code snippet?#include <stdio.h>void solve() { int first = 10, second = 20; int third = first + second; { int third = second - first; printf("%d ", third); } printf("%d", third);}int main() { solve(); return 0;}a)10 30b)30 10c)10 20d)20 10Correct answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice What will be the output of the following code snippet?#include <stdio.h>void solve() { int first = 10, second = 20; int third = first + second; { int third = second - first; printf("%d ", third); } printf("%d", third);}int main() { solve(); return 0;}a)10 30b)30 10c)10 20d)20 10Correct answer is option 'A'. Can you explain this answer? tests, examples and also practice Electrical Engineering (EE) tests.
Explore Courses for Electrical Engineering (EE) exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev